//
//  HYTabBarController.m
//  _normal
//
//  Created by Ezra on 16/5/29.
//  Copyright © 2016年 Ezra. All rights reserved.
//

#import "HYTabBarController.h"
#import "HYNavigationController.h"



#import "WorshipbuddaViewController.h"
#import "FormtiesViewController.h"
#import "AnswerViewController.h"

#import "WorshipbuddaViewController.h"


@interface HYTabBarController ()<UITabBarControllerDelegate>

@property (nonatomic, weak) UIViewController *lastViewController;

@end

@implementation HYTabBarController

+ (void)load
{
    //🏁Appearance要在控件显示之前就要设置
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    [item setTitleTextAttributes:attr forState:UIControlStateNormal];
    
    
    NSMutableDictionary *attC = [NSMutableDictionary dictionary];
    attC[NSForegroundColorAttributeName] = PrimaryYellow;
    [item setTitleTextAttributes:attC forState:UIControlStateSelected];
    
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupAllChildViewController];
    
//    [self setPlusButton];
    
    NSString *PATH = NSHomeDirectory();
    NSLog(@"%@",PATH);
    
    self.tabBar.tintColor = PrimaryYellow;
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    self.delegate = self;
}

- (void)setupAllChildViewController
{
    //解惑
      [self setupOneChildViewController:[[HYNavigationController alloc]initWithRootViewController:[[AnswerViewController alloc]init]] title:@"解惑" image:@"ic_tab_strip_icon01" selImage:@"ic_tab_strip_icon01"];


    
    //结缘
    [self setupOneChildViewController:[[HYNavigationController alloc]initWithRootViewController:[[FormtiesViewController alloc]init]] title:@"结缘" image:@"ic_tab_strip_icon02" selImage:@"ic_tab_strip_icon02"];
    
    //礼佛
      [self setupOneChildViewController:[[HYNavigationController alloc]initWithRootViewController:[[WorshipbuddaViewController alloc]init]] title:@"礼佛" image:@"ic_tab_strip_icon03" selImage:@"ic_tab_strip_icon03"];
    
    

    
}

- (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selImage:(NSString *)selImage
{
    vc.tabBarItem.title = title;
    
    if (image.length) {
        
        vc.tabBarItem.image = [UIImage imageNamed:image];
        vc.tabBarItem.selectedImage = [UIImage imageNamed:selImage];

    }
    
    [self addChildViewController:vc];
}

- (void)setPlusButton
{
    UIButton *plusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [plusBtn setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
    [plusBtn setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
    [plusBtn addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
    
    [plusBtn sizeToFit];
    
    plusBtn.center = CGPointMake(self.tabBar.HY_width * 0.5, self.tabBar.HY_height * 0.5);
    
    [self.tabBar addSubview:plusBtn];
    
}

//tabbar上面按钮的点击代理
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (_lastViewController == viewController) {
        NSLog(@"点击了tabbar");
        [[NSNotificationCenter defaultCenter] postNotificationName:repeateClickTabBarButtonNotification object:nil];
    }
    
    _lastViewController =viewController;
    
}


- (void)clickButton
{
    NSLog(@"%s %d",__func__, __LINE__);
}

@end
